package com.air;

/**
 * User: Aruna Rajapaksha
 */

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AuthenticationController extends HttpServlet {

    public void doPost(HttpServletRequest request,
                       HttpServletResponse response)
            throws IOException, ServletException {

        String userName = request.getParameter("txtUserName");
        String password = request.getParameter("txtPassword");

        // Now use the Authenticate Model
        AuthenticationModel model = new AuthenticationModel();

        String status = model.doAuthenticate(userName, password);

        // Use the below code to debug the program if you get problems
        //response.setContentType("text/html");
        //PrintWriter out = response.getWriter();
        //out.println("Authenticate Status for " + userName + " and " + password + "<br>");
        //out.print("<br>Status: " + status);

        // The results will be passed back (as an attribute) to the JSP view
        // The attribute will be a name/value pair, the value in this case will be a List object
        request.setAttribute("status", status);
        RequestDispatcher view = request.getRequestDispatcher("status.jsp");
        view.forward(request, response);
    }
}